package com.ziyun.pop.web.modules.mercharReport.controller;

import com.ziyun.pop.common.utils.FileUtil;
import com.ziyun.pop.common.utils.JsonUtils;
import com.ziyun.pop.common.utils.UserUtils;
import com.ziyun.pop.modules.mercharReport.entity.ReportStoreMemberVO;
import com.ziyun.pop.modules.mercharReport.service.ReportStoreMemberService;
import io.renren.common.utils.R;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 门店会员预存款汇总表
 *
 * @author jiangli
 * @email
 * @date 2018-10-16 17:50:05
 */
@RestController
@RequestMapping("mercharReport/storemember")
public class ReportStoreMemberController {
    @Autowired
    private ReportStoreMemberService storeMemberService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("mercharReport:storemember:list")
    public R list(@RequestParam Map<String, Object> params) {
        SysUserEntity curentUser = UserUtils.getCurentUser();
        params.put("sellerId", curentUser.getSellerId());
        return storeMemberService.list(params);
    }

    /**
     * excel 导出
     */
    @RequestMapping("/exportExcel")
    public void exportExcel(HttpServletRequest request, HttpServletResponse response) {
        String data = request.getParameter("postData");
        Map<String, Object> params = JsonUtils.string2Map(data);
        params.put("sellerId", UserUtils.getCurentUser().getSellerId());
        // 查询列表数据
        List<ReportStoreMemberVO> list = storeMemberService.exportExcel(params);
        FileUtil.exportExcel(list, "门店会员预存款汇总表", "门店会员预存款汇总表", ReportStoreMemberVO.class, "门店会员预存款汇总表.xls", response);
    }
}
